package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Reference
    PermissionService permissionService;
    //查询所有权限信息
    @RequestMapping("/findAll.do")
    public Result findAll() {
        log.debug("```````````````````````这里是权限查询所有的查询所有方法,被访问了");
        Set<Permission> permissions = permissionService.findAll();
        log.debug("``````````````````````执行权限的查询所有方法成功返回权限集合对象:"+permissions);
        return new Result(true,MessageConst.ACTION_SUCCESS,permissions);
    }
    @RequestMapping("/findPermissionByRoleId.do")
    public Result findPermissionByRoleId(Integer id) {
        log.debug("```````````````````````这里是权限的根据角色查找对应的权限方法,被访问了");
        Set<Integer> permissions = permissionService.findPermissionByRoleId(id);
        log.debug("``````````````````````执行权限的根据角色查找对应的权限方法成功返回权限集合对象:" + permissions);
        return new Result(true, MessageConst.ACTION_SUCCESS, permissions);


    }



    @RequestMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean){
log.debug("--------------------------------------------------------------------------");
        PageResult pageResult = permissionService.findByPage(queryPageBean);
        log.debug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        return new Result(true, "查询分页成功",pageResult);
    }

    @RequestMapping("/delById")
    public Result delById(Integer id){

        permissionService.delById(id);
        return new Result(true,"删除权限信息成功");
    }


    @RequestMapping("/findById")
    public Result findById(Integer id) {

        Permission permission = permissionService.findById(id);
        return new Result(true, "查询权限信息成功",permission);
    }


    @RequestMapping("/add")
    public Result add(@RequestBody Permission permission){

       permissionService.add(permission);
        return new Result(true,"添加权限信息成功");
    }
    @RequestMapping("/edit")
    public Result edit(@RequestBody Permission permission){

            permissionService.edit(permission);
            return new Result(true, "修改权限信息成功");

        }
}
